import 'dart:convert';

import 'package:http/http.dart' as http;

class API{
  static String ip = "http://172.16.8.13:3100";

  static var book_list = [];
  static var xp_dic = {};
  static var music_url = "";

  static Future<void> get_book_list_api() async {
    var req = await http.get(Uri.parse("${ip}/api/books"));
    if(req.statusCode == 200){
      var dic = json.decode(req.body);
      if(dic["code"] == 200){
        book_list = dic["data"];
      }
      else{
        print("1-2");
      }
    }
    else{
      print("1");
    }
  }


  static Future<void> get_xp_dic_api(String book_id) async {
    var req = await http.get(Uri.parse("${ip}/api/books/${book_id}"));
    if(req.statusCode == 200){
      var dic = json.decode(req.body);
      if(dic["code"] == 200){
        xp_dic = dic["data"];
      }
      else{
        print("2-2");
      }
    }
    else{
      print("2");
    }
  }

  static Future<void> get_music_url_api(String book_id) async {
    var req = await http.get(Uri.parse("${ip}/audio/${book_id}.mp3"));
    if(req.statusCode == 200){
      music_url = "${ip}/audio/${book_id}.mp3";
    }
    else{
      music_url = "";
    }
  }


}